<template>
	<view class="login-container">
		<view class="wechatapp">
			<view class="header">
				<!-- #ifdef MP-WEIXIN -->
				<open-data class="" type="userAvatarUrl"></open-data>
				<!-- #endif -->
			</view>
		</view>
		<view class="auth-title">申请获取以下权限</view>
		<view class="auth-subtitle">获得你的公开信息（昵称、头像等）</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				code: '',
			}
		},
    onShow() {

    },
		onLoad(e) {
      this.code = this.getUrlCode().code; // 截取code
      this.getUserInfo()
		},
		methods: {
			getUserInfo: function() {
				let self = this;
        let code = self.code;
        let token = uni.getStorageSync('token');
        if(!code || token){
          this.gotoPage("/pages/index/index");
          return;
        }
        self._post('user.usermp/login', {
          code: code,
        }, result => {
          // 记录token user_id
          uni.setStorageSync('token', result.data.token);
          uni.setStorageSync('user_id', result.data.user_id);
          // 执行回调函数
          this.gotoPage("/pages/index/index");
        }, false, () => {
          uni.hideLoading();
        });
			},
		},
	}
</script>

<style>
	.login-container {
		padding: 30rpx;
	}

	.wechatapp {
		padding: 80rpx 0 48rpx;
		border-bottom: 1rpx solid #e3e3e3;
		margin-bottom: 72rpx;
		text-align: center;
	}

	.wechatapp .header {
		width: 190rpx;
		height: 190rpx;
		border: 2px solid #fff;
		margin: 0rpx auto 0;
		border-radius: 50%;
		overflow: hidden;
		box-shadow: 1px 0px 5px rgba(50, 50, 50, 0.3);
	}

	.auth-title {
		color: #585858;
		font-size: 34rpx;
		margin-bottom: 40rpx;
	}

	.auth-subtitle {
		color: #888;
		margin-bottom: 88rpx;
		font-size: 28rpx;
	}

	.login-btn {
		padding: 0 20rpx;
	}

	.login-btn button {
		height: 88rpx;
		line-height: 88rpx;
		background: #04be01;
		color: #fff;
		font-size: 30rpx;
		border-radius: 999rpx;
		text-align: center;
	}

	.no-login-btn {
		margin-top: 20rpx;
		padding: 0 20rpx;
	}

	.no-login-btn button {
		height: 88rpx;
		line-height: 88rpx;
		background: #dfdfdf;
		color: #fff;
		font-size: 30rpx;
		border-radius: 999rpx;
		text-align: center;
	}
</style>
